package round86;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * User: Samuel
 * Date: 09-08-11
 * Time: 10:12 AM
 */
public class B {
    public static void main(String[] args) throws IOException {
        new B().run();
    }

    private void run() throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String split[] = in.readLine().split(" ");
        int n = Integer.parseInt(split[0]);
        int m = Integer.parseInt(split[1]);
        List<String> names = new ArrayList<String>();
        for (int i = 0; i < n; i++) {
            names.add(in.readLine());
        }
        Set<String> set = new HashSet<String>();
        Map<String, List<Node>> map = new HashMap<String, List<Node>>();
        List<Node> nodes = new ArrayList<Node>();
        for (int i = 0; i < m; i++) {
            split = in.readLine().split(" ");
            if(set.add(split[0])){
                Node node = new Node(split[0]);
                nodes.add(node);
                List<Node> l = new ArrayList<Node>();
                if(set.add(split[1])) {
                    
                }
                l.add(null);
                map.put(split[0], new ArrayList<Node>());
            }else {
                if (set.add(split[1])) {
                    Node node = new Node(split[1]);
                    nodes.add(node);
                }
                map.get(split[0]).add(null);
            }

        }
    }
}

class Node {
    String nm;
    int color = 0;

    Node(String name, int c) {
        nm = name;
        color = c;
    }

    Node(String name) {
        nm = name;
    }

}